import { Cloud } from 'laf-client-sdk'
import { useUserStore } from '@/store/modules/user'
const userStore = useUserStore()
const cloud = new Cloud({
  baseUrl: 'https://su75ks.laf.run', // <APP_ID> 在首页应用列表获取
  getAccessToken: () => userStore.token, // 这里不需要授权，先填空
})

//获取审核信息
export async function getApproval() {
  const res = await cloud.invoke('curd_op', {
    collection: 'Apply_Inf',
    operation: 'get',
    data: {
      orderBy: {
        upload_date: 'desc',
      },
    },
  })
  return res
}

//文件审核信息分页查询
export async function getApplyInfo(page, pageSize, _id) {
  const res = await cloud.invoke('curd_op', {
    collection: 'Apply_Inf',
    operation: 'get',
    data: {
      where: {
        person_id: _id,
      },
      skip: (page - 1) * pageSize,
      limit: pageSize,
      orderBy: {
        upload_date: 'desc',
      },
    },
  })
  return res
}

//获取一条特定
export async function getSpecialApply(person_id, name) {
  const res = await cloud.invoke('curd_op', {
    collection: 'Apply_Inf',
    operation: 'get',
    data: {
      where: {
        person_id: person_id,
        name: name,
      },
    },
  })
  return res
}
